# coding:utf8


from PyQt5.QtWidgets import QMenu, QAction

class ProxyMenu:
    def __init__(self):
        self.menu = QMenu()
        self.item_f_dict = {}
    
    def add(self, action_str, f_action, icon = None):
        if icon:
            item = self.menu.addAction(icon, action_str)
        else:
            item = self.menu.addAction(action_str)
        self.item_f_dict.setdefault(item, f_action)
        
    def exec(self, Parent, pos):
        curitem = self.menu.exec_(Parent.mapToGlobal(pos))
        # run action function
        self.item_f_dict.get(curitem, lambda : ... )()
        
    def add_separator(self):
        self.menu.addSeparator()
        
        
        
        
        
        

